package com.zhiyou100.modify3;

/**
 * public修饰的People类，可以通过对构造方法的权限限制，
 * 进而达到对People对象的限制
 */
public class People {

    private String name;
    private int age;
    private char sex;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    //默认的公开的无参构造,此时我们可以通过修改构造方法的访问权限达到控制对象创建的权限
    private People(){
        System.out.println("这是一个用私有权限修饰符修饰的构造方法");
    }

    //如果我们的构造方法被权限修饰符进行了限制，而我们还想外界能创建此对象
    public static People getInstance(){
        return new People();
    }

    public static void main(String[] args) {
        People people = new People();
    }


}
